package cn.hj.controller;

import cn.hj.beans.School;
import cn.hj.mapper.SchoolMapper;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperFactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class MyController {

    @Autowired
    private MapperFactoryBean<SchoolMapper> schoolMapper;


    @ResponseBody
    @RequestMapping(value="/school/{id}")
    public String getSchool(@PathVariable("id") int id) throws Exception {
        SchoolMapper mapper=schoolMapper.getObject();
        School s = mapper.getSchoolById(id);
        System.out.println(s);
        return s.toString();
    }

    @RequestMapping("/hello")
    public String hello(){
        return "hello";
    }

}
